// $codepro.audit.disable numericLiterals
/**
 * uses view package
 */
package javamonsters.view;

import java.awt.Dimension;

import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import javax.swing.JLabel;

import java.awt.FontFormatException;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Font;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JSlider;
import java.io.File;
import java.io.IOException;
import java.awt.Color;

/**
 * View for ShipYard
 * 
 * @author elahurd3
 * @version 1.0
 */
public class ShipYardView extends JPanel {
	
	/**
	 * JLabels 
	 */
	private final JLabel currentShipLabel, systemLabel, techLevelLabel, 
	creditsLabel, currentFuelLabel, fuelToBuyLabel, fuelCostLabel;
	
	/**
	 * JButton
	 */
	private final JButton buyShipButton, toMarketButton, saveButton, 
	backToMapButton, buyFuelButton;
	
	/**
	 * slider for fuel purchase
	 */
	private final JSlider fuelSlider;
	
	/**
	 * JList of ships
	 */
	private final JList shipList;
	
	/**
	 * default list model for ship list
	 */
	private final DefaultListModel shipListModel;
	
	/**
	 * fonts
	 */
	private final Font listTitleFont, headerFont, infoFont, buttonFont;
	
	/**
	 * Constructor for the view of shipyard
	 * @throws FontFormatException
	 * @throws IOException
	 */
	public ShipYardView() throws FontFormatException, IOException {
		super.setPreferredSize(new Dimension(700, 380));
		super.setLayout(new GridLayout(1, 3, 0, 0));
		
		final File fontFile = new File("Fonts/Compass.ttf");
		final Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
		listTitleFont = font.deriveFont(14f);
		headerFont = font.deriveFont(18f);
		infoFont = font.deriveFont(10f);
		buttonFont = font.deriveFont(12f);
		
		final JPanel purchasePanel = new JPanel();
		super.add(purchasePanel);
		purchasePanel.setLayout(new GridLayout(2, 1, 0, 0));
		
		final JPanel shipPanel = new JPanel();
		purchasePanel.add(shipPanel);
		shipPanel.setLayout(new GridLayout(1, 0, 0, 0));
		
		final JScrollPane scrollPane = new JScrollPane();
		shipPanel.add(scrollPane);
		
		shipListModel = new DefaultListModel();
		shipList = new JList(shipListModel);
		shipList.setForeground(Color.WHITE);
		shipList.setBackground(Color.BLACK);
		shipList.setFont(buttonFont);
		scrollPane.setViewportView(shipList);
		final JLabel shipListLabel = new JLabel("Available Ships");
		shipListLabel.setFont(listTitleFont);
		scrollPane.setColumnHeaderView(shipListLabel);
		
		final JPanel shipBuyPanel = new JPanel();
		shipBuyPanel.setBackground(Color.BLACK);
		purchasePanel.add(shipBuyPanel);
		final GridBagLayout gbl_shipBuyPanel = new GridBagLayout();
		gbl_shipBuyPanel.columnWidths = new int[]{120, 113, 0};
		gbl_shipBuyPanel.rowHeights = new int[]{43, 0, 32, 0, 0};
		gbl_shipBuyPanel.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		gbl_shipBuyPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		shipBuyPanel.setLayout(gbl_shipBuyPanel);
		
		buyShipButton = new JButton("Buy New Ship");
		buyShipButton.setFont(buttonFont);
		final GridBagConstraints gbc_buyShipButton = new GridBagConstraints();
		gbc_buyShipButton.gridwidth = 2;
		gbc_buyShipButton.insets = new Insets(0, 0, 5, 0);
		gbc_buyShipButton.gridx = 0;
		gbc_buyShipButton.gridy = 1;
		shipBuyPanel.add(buyShipButton, gbc_buyShipButton);
		
		final JLabel currentShipTagLabel = new JLabel("Current Ship: ");
		currentShipTagLabel.setForeground(Color.WHITE);
		currentShipTagLabel.setFont(infoFont);
		final GridBagConstraints gbc_currentShipTagLabel = new GridBagConstraints();
		gbc_currentShipTagLabel.insets = new Insets(0, 0, 0, 5);
		gbc_currentShipTagLabel.gridx = 0;
		gbc_currentShipTagLabel.gridy = 3;
		shipBuyPanel.add(currentShipTagLabel, gbc_currentShipTagLabel);
		
		currentShipLabel = new JLabel("Ship");
		currentShipLabel.setForeground(Color.WHITE);
		currentShipLabel.setFont(infoFont);
		final GridBagConstraints gbc_currentShipLabel = new GridBagConstraints();
		gbc_currentShipLabel.gridx = 1;
		gbc_currentShipLabel.gridy = 3;
		shipBuyPanel.add(currentShipLabel, gbc_currentShipLabel);
		
		final JPanel buttonPanel = new JPanel();
		buttonPanel.setBackground(Color.BLACK);
		super.add(buttonPanel);
		final GridBagLayout gbl_buttonPanel = new GridBagLayout();
		gbl_buttonPanel.columnWidths = new int[]{118, 120, 0};
		gbl_buttonPanel.rowHeights = new int[]{60, 60, 60, 24, 43, 0, 0, 25, 22, 14, 0};
		gbl_buttonPanel.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		gbl_buttonPanel.rowWeights = new double[]{
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		buttonPanel.setLayout(gbl_buttonPanel);
		
		systemLabel = new JLabel("System");
		systemLabel.setForeground(Color.WHITE);
		systemLabel.setFont(headerFont);
		final GridBagConstraints gbc_systemLabel = new GridBagConstraints();
		gbc_systemLabel.gridwidth = 2;
		gbc_systemLabel.insets = new Insets(0, 0, 5, 0);
		gbc_systemLabel.gridx = 0;
		gbc_systemLabel.gridy = 0;
		buttonPanel.add(systemLabel, gbc_systemLabel);
		
		final JLabel shipYardLabel = new JLabel("Ship Yard");
		shipYardLabel.setForeground(Color.WHITE);
		shipYardLabel.setFont(headerFont);
		final GridBagConstraints gbc_shipYardLabel = new GridBagConstraints();
		gbc_shipYardLabel.gridwidth = 2;
		gbc_shipYardLabel.insets = new Insets(0, 0, 5, 0);
		gbc_shipYardLabel.gridx = 0;
		gbc_shipYardLabel.gridy = 1;
		buttonPanel.add(shipYardLabel, gbc_shipYardLabel);
		
		final JLabel techLevelTagLabel = new JLabel("Tech Level:");
		techLevelTagLabel.setForeground(Color.WHITE);
		techLevelTagLabel.setFont(infoFont);
		final GridBagConstraints gbc_techLevelTagLabel = new GridBagConstraints();
		gbc_techLevelTagLabel.insets = new Insets(0, 0, 5, 5);
		gbc_techLevelTagLabel.gridx = 0;
		gbc_techLevelTagLabel.gridy = 2;
		buttonPanel.add(techLevelTagLabel, gbc_techLevelTagLabel);
		
		techLevelLabel = new JLabel("Level");
		techLevelLabel.setForeground(Color.WHITE);
		techLevelLabel.setFont(infoFont);
		final GridBagConstraints gbc_techLevelLabel = new GridBagConstraints();
		gbc_techLevelLabel.anchor = GridBagConstraints.WEST;
		gbc_techLevelLabel.insets = new Insets(0, 0, 5, 0);
		gbc_techLevelLabel.gridx = 1;
		gbc_techLevelLabel.gridy = 2;
		buttonPanel.add(techLevelLabel, gbc_techLevelLabel);
		
		final JLabel creditsTagLabel = new JLabel("Available Credits: ");
		creditsTagLabel.setForeground(Color.WHITE);
		creditsTagLabel.setFont(infoFont);
		final GridBagConstraints gbc_creditsTagLabel = new GridBagConstraints();
		gbc_creditsTagLabel.insets = new Insets(0, 0, 5, 5);
		gbc_creditsTagLabel.gridx = 0;
		gbc_creditsTagLabel.gridy = 3;
		buttonPanel.add(creditsTagLabel, gbc_creditsTagLabel);
		
		creditsLabel = new JLabel("Credits");
		creditsLabel.setForeground(Color.WHITE);
		creditsLabel.setFont(infoFont);
		final GridBagConstraints gbc_creditsLabel = new GridBagConstraints();
		gbc_creditsLabel.anchor = GridBagConstraints.WEST;
		gbc_creditsLabel.insets = new Insets(0, 0, 5, 0);
		gbc_creditsLabel.gridx = 1;
		gbc_creditsLabel.gridy = 3;
		buttonPanel.add(creditsLabel, gbc_creditsLabel);
		
	    toMarketButton = new JButton("To Marketplace");
	    toMarketButton.setFont(buttonFont);
	    final GridBagConstraints gbc_toMarketButton = new GridBagConstraints();
	    gbc_toMarketButton.insets = new Insets(0, 0, 5, 0);
	    gbc_toMarketButton.gridwidth = 2;
	    gbc_toMarketButton.gridx = 0;
	    gbc_toMarketButton.gridy = 6;
	    buttonPanel.add(toMarketButton, gbc_toMarketButton);
		
		saveButton = new JButton("Save");
		saveButton.setFont(buttonFont);
		final GridBagConstraints gbc_saveButton = new GridBagConstraints();
		gbc_saveButton.insets = new Insets(0, 0, 5, 0);
		gbc_saveButton.gridwidth = 2;
		gbc_saveButton.gridx = 0;
		gbc_saveButton.gridy = 7;
		buttonPanel.add(saveButton, gbc_saveButton);
		
		backToMapButton = new JButton("Back To Universe Map");
		backToMapButton.setFont(buttonFont);
		final GridBagConstraints gbc_backToMapButton = new GridBagConstraints();
		gbc_backToMapButton.insets = new Insets(0, 0, 5, 0);
		gbc_backToMapButton.gridwidth = 2;
		gbc_backToMapButton.gridx = 0;
		gbc_backToMapButton.gridy = 8;
		buttonPanel.add(backToMapButton, gbc_backToMapButton);
		
		final JPanel fuelCostPanel = new JPanel();
		fuelCostPanel.setBackground(Color.BLACK);
		super.add(fuelCostPanel);
		final GridBagLayout gbl_fuelCostPanel = new GridBagLayout();
		gbl_fuelCostPanel.columnWidths = new int[]{81, 78, 78, -2};
		gbl_fuelCostPanel.rowHeights = new int[]{60, 60, 57, 24, 28, 25, 40, 36, 0};
		gbl_fuelCostPanel.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_fuelCostPanel.rowWeights = new double[]{
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		fuelCostPanel.setLayout(gbl_fuelCostPanel);
		
		final JLabel fuelStationLabel = new JLabel("Fuel Station");
		fuelStationLabel.setForeground(Color.WHITE);
		fuelStationLabel.setFont(headerFont);
		final GridBagConstraints gbc_fuelStationLabel = new GridBagConstraints();
		gbc_fuelStationLabel.insets = new Insets(0, 0, 5, 0);
		gbc_fuelStationLabel.gridwidth = 3;
		gbc_fuelStationLabel.gridx = 0;
		gbc_fuelStationLabel.gridy = 0;
		fuelCostPanel.add(fuelStationLabel, gbc_fuelStationLabel);
		
		currentFuelLabel = new JLabel("Current Fuel:    Fuel");
		currentFuelLabel.setForeground(Color.WHITE);
		currentFuelLabel.setFont(infoFont);
		final GridBagConstraints gbc_curentFuelLabel = new GridBagConstraints();
		gbc_curentFuelLabel.gridwidth = 3;
		gbc_curentFuelLabel.insets = new Insets(0, 0, 5, 0);
		gbc_curentFuelLabel.gridx = 0;
		gbc_curentFuelLabel.gridy = 1;
		fuelCostPanel.add(currentFuelLabel, gbc_curentFuelLabel);
		
		final JLabel selectAmountLabel = new JLabel("Select Amount Of Fuel To Buy:");
		selectAmountLabel.setForeground(Color.WHITE);
		selectAmountLabel.setFont(infoFont);
		final GridBagConstraints gbc_selectAmountLabel = new GridBagConstraints();
		gbc_selectAmountLabel.gridwidth = 3;
		gbc_selectAmountLabel.insets = new Insets(0, 0, 5, 0);
		gbc_selectAmountLabel.gridx = 0;
		gbc_selectAmountLabel.gridy = 2;
		fuelCostPanel.add(selectAmountLabel, gbc_selectAmountLabel);
		
		fuelToBuyLabel = new JLabel("0");
		fuelToBuyLabel.setForeground(Color.WHITE);
		fuelToBuyLabel.setFont(infoFont);
		final GridBagConstraints gbc_fuelToBuyLabel = new GridBagConstraints();
		gbc_fuelToBuyLabel.insets = new Insets(0, 0, 5, 5);
		gbc_fuelToBuyLabel.gridx = 1;
		gbc_fuelToBuyLabel.gridy = 3;
		fuelCostPanel.add(fuelToBuyLabel, gbc_fuelToBuyLabel);
		
		fuelSlider = new JSlider(0, 20);
		fuelSlider.setForeground(Color.WHITE);
		fuelSlider.setBackground(Color.BLACK);
		final GridBagConstraints gbc_fuelSlider = new GridBagConstraints();
		gbc_fuelSlider.fill = GridBagConstraints.HORIZONTAL;
		gbc_fuelSlider.gridwidth = 3;
		gbc_fuelSlider.insets = new Insets(0, 0, 5, 0);
		gbc_fuelSlider.gridx = 0;
		gbc_fuelSlider.gridy = 4;
		fuelCostPanel.add(fuelSlider, gbc_fuelSlider);
		
		buyFuelButton = new JButton("Buy Fuel");
		buyFuelButton.setFont(buttonFont);
		final GridBagConstraints gbc_buyFuelButton = new GridBagConstraints();
		gbc_buyFuelButton.insets = new Insets(0, 0, 5, 0);
		gbc_buyFuelButton.gridwidth = 3;
		gbc_buyFuelButton.gridx = 0;
		gbc_buyFuelButton.gridy = 6;
		fuelCostPanel.add(buyFuelButton, gbc_buyFuelButton);
		
		final JLabel fuelCostTagLabel = new JLabel("Cost: ");
		fuelCostTagLabel.setForeground(Color.WHITE);
		fuelCostTagLabel.setFont(infoFont);
		final GridBagConstraints gbc_fuelCostTagLabel = new GridBagConstraints();
		gbc_fuelCostTagLabel.insets = new Insets(0, 0, 0, 5);
		gbc_fuelCostTagLabel.gridx = 0;
		gbc_fuelCostTagLabel.gridy = 7;
		fuelCostPanel.add(fuelCostTagLabel, gbc_fuelCostTagLabel);
		
		fuelCostLabel = new JLabel("0");
		fuelCostLabel.setForeground(Color.WHITE);
		fuelCostLabel.setFont(infoFont);
		final GridBagConstraints gbc_fuelCostLabel = new GridBagConstraints();
		gbc_fuelCostLabel.insets = new Insets(0, 0, 0, 5);
		gbc_fuelCostLabel.gridx = 1;
		gbc_fuelCostLabel.gridy = 7;
		fuelCostPanel.add(fuelCostLabel, gbc_fuelCostLabel);
		
		final JLabel creditsWordLabel = new JLabel("credits");
		creditsWordLabel.setForeground(Color.WHITE);
		creditsWordLabel.setFont(infoFont);
		final GridBagConstraints gbc_creditsWordLabel = new GridBagConstraints();
		gbc_creditsWordLabel.gridx = 2;
		gbc_creditsWordLabel.gridy = 7;
		fuelCostPanel.add(creditsWordLabel, gbc_creditsWordLabel);
	
	}
	
	/**
	 * @return button that allows player to buy a ship
	 */
	public JButton getBuyShipButton() {
		return buyShipButton;
	}
	
	/**
	 * @return return button that takes player to marketplace
	 */
	public JButton getToMarketButton() {
		return toMarketButton;
	}
	
	/**
	 * @return button that brings up save/exit save
	 */
	public JButton getSaveButton() {
		return saveButton;
	}
	
	/**
	 * @return return button that takes player back to universe map 
	 */
	public JButton getBackToMapButton() {
		return backToMapButton;
	}
	
	/**
	 * @return button that allows player to buy fuel
	 */
	public JButton getBuyFuelButton() {
		return buyFuelButton;
	}
	
	/**
	 * @return label that displays the player's current ship
	 */
	public JLabel getCurrentShipLabel() {
		return currentShipLabel;
	}
	
	/**
	 * @return label that displays the system the player is currently in
	 */
	public JLabel getSystemLabel() {
		return systemLabel;
	}
	
	/**
	 * @return label that displays the tech level of the system the player is currently in
	 */
	public JLabel getTechLevelLabel() {
		return techLevelLabel;
	}
	
	/**
	 * @return the label that displays the number of credits the player currently has
	 */
	public JLabel getCreditsLabel() {
		return creditsLabel;
	}
	
	/**
	 * @return the label that displays the amount of fuel the 
	 * player currently has in his/her ship
	 */
	public JLabel getCurrentFuelLabel() {
		return currentFuelLabel;
	}
	
	/**
	 * @return the label that displays the cost of the amount of 
	 * fuel the player has currently selected on the fuel slider
	 */
	public JLabel getFuelCostLabel() {
		return fuelCostLabel;
	}
	
	/**
	 * @return the label that displays how much fuel the
	 *  player has selected from the slider
	 */
	public JLabel getFuelToBuyLabel() {
		return fuelToBuyLabel;
	}
	
	/**
	 * @return the slider that allows the player select how much fuel he/she wants to buy
	 */
	public JSlider getFuelSlider() {
		return fuelSlider;
	}
	
	/**
	 * @return the JList that contains the list of possible ships the player can buy
	 */
	public JList getShipList() {
		return shipList;
	}
	
	/**
	 * @return the default list model that is the model for the 
	 * JList of possible ships the player can buy
	 */
	public DefaultListModel getShipListModel() {
		return shipListModel;
	}
	

}
